#ifndef __D3D10RENDERER__
#define __D3D10RENDERER__

#include <windows.h>
#include <d3d10.h>
#include "baserenderer.h"
#include "dxcommon.h"

typedef HRESULT (__stdcall *D3D10CreateStateBlock_Type)(ID3D10Device *pDevice,
  D3D10_STATE_BLOCK_MASK *pStateBlockMask, ID3D10StateBlock **ppStateBlock);

class D3D10Renderer : public BaseRenderer
{
  class D3D10Texture : public BaseTexture
  {
  public:
    ID3D10Texture2D* pTexture;
    ID3D10ShaderResourceView* pView;
    int width;
    int height;
    int size;
    D3D10Texture()
      : pTexture(NULL)
      , pView(NULL)
      , size(0)
    {}
    ~D3D10Texture()
    {
      COMRELEASE(pTexture);
      COMRELEASE(pView);
    }
  };
  struct Vertex
  {
    float x, y, z;
    float r, g, b, a;
    float u, v;
  };

  D3D10CreateStateBlock_Type CreateStateBlock;
  D3D10_STATE_BLOCK_MASK stateBlockMask;

  IDXGISwapChain* pCurSwapChain;
  ID3D10Device* pCurDevice;
  ID3D10StateBlock* pStateBlock;
  ID3D10InputLayout* pInputLayout;
  ID3D10VertexShader* pVertexShader;
  ID3D10PixelShader* pPixelShader;
  ID3D10Buffer* pVertexBuffer;
  ID3D10Buffer* pIndexBuffer;
  ID3D10Buffer* pConstantBuffer;

  ID3D10BlendState* pBlendState;
  ID3D10DepthStencilState* pDepthState;
  ID3D10RasterizerState* pRasterizerState;
  ID3D10SamplerState* pSamplerState;

  BaseTexture* newTexture()
  {
    return new D3D10Texture;
  }
  bool updateTexture(BaseTexture* tex, ImageHeader* image);
  void drawRect(BaseTexture* tex, int left, int top, int right, int bottom, unsigned long color);
  void setViewport(int left, int top, int right, int bottom);
  void reset();

  HWND getDeviceWindow(IDXGISwapChain* pSwapChain);
public:
  D3D10Renderer(OverlayState const* pState);
  ~D3D10Renderer();

  void render(IDXGISwapChain* pSwapChain, ID3D10Device* pDevice);
  void onDestroy(HWND hWnd);
};

#endif // __D3D10RENDERER__
